{% extends "rules/base.html" %}
{% block sidebar %}
    <div class="panel-heading">
        <h2 class="panel-title">{{ threshold.threshold_type }} {{ threshold.pk }}</h2>
    </div>
    <div class="panel-body">
        <ul>
            <li>
                Ruleset:
                <a href="{% url 'ruleset' threshold.ruleset.pk %}">{{ threshold.ruleset.name }}</a>
            </li>
            <li>
                Signature:
                <a href="{% url 'rule' threshold.rule.sid %}">{{ threshold.rule.msg }}</a>
            </li>
        </ul>
    </div>
    <div class="panel-heading">
        <h2 class="panel-title">Actions</h2>
    </div>
    {% if perms.rules.ruleset_policy_edit %}
        <div class="panel-body">
            <ul class="action">
                <li>
                    <a href="{% url 'delete_threshold' threshold.pk %}">Delete</a>
                </li>
                <li>
                    <a href="{% url 'edit_threshold' threshold.pk %}">Edit</a>
                </li>
            </ul>
        </div>
    {% endif %}
{% endblock sidebar %}
{% block content %}
    <h2>
        {{ threshold.threshold_type.title }} for
        <a href="{% url 'rule' threshold.rule.sid %}">{{ threshold.rule.sid }}</a>
    </h2>
    {% if threshold.threshold_type == "suppress" %}
        <p>
            Alert is suppressed for
            {% if threshold.track_by == 'by_src' %}
                source {{ threshold.net }}
            {% elif threshold.track_by == 'by_dst' %}
                destination {{ threshold.net }}
            {% else %}
                address {{ threshold.net }}
            {% endif %}
        </p>
    {% else %}
        <p>
            Alert is limited
            {% if threshold.track_by == 'by_src' %}
                by source
            {% elif threshold.track_by == 'by_dst' %}
                by destination
            {% else %}
                by source or destination
            {% endif %}
            to
            {{ threshold.count }} per {{ threshold.seconds }} seconds.
        </p>
    {% endif %}
    <h2>{{ threshold.threshold_type.title }} expression</h2>
    <div class="rule">{{ threshold.highlight_content|safe }}</div>
    <h2>Signature</h2>

    <ul class="nav nav-tabs" id="rule-info">
        {% for rav in rule_at_versions %}
            <li class="{% if forloop.first %}active{% endif %}">
                <a href="#version_{{ rav.version }}">
                    {% if rav.version < 39 %}< v39 {% else %}v{{ rav.version }}{% endif %}
                </a>
            </li>
        {% endfor %}
    </ul>
    <div class="tab-content">
        {% for rav in rule_at_versions %}
            <div class="tab-pane fade {% if forloop.first %}active{% endif %} in" id="version_{{ rav.version }}">
                <div class="rule">{{ rav.content|safe }}</div>
            </div>
        {% endfor %}
    </div>

    <script>
$(document).ready(function(){
    var activeTab = localStorage.getItem('thresholdRuleTab');
    if(activeTab){
        $('#rule-info li').siblings().removeClass('active');
        $('#rule-info a[href="' + activeTab + '"]').tab('show');
        $('#rule-info a[href="' + activeTab + '"]').closest('li').addClass('active');
    }

    $("ul.nav-tabs a").click(function (e) {
        e.preventDefault();
        $(this).closest('li').siblings().removeClass('active');
        $(this).closest('li').addClass('active');
        $(this).tab('show');
        localStorage.setItem('thresholdRuleTab', $(e.target).attr('href'));
    });
});
    </script>

{% endblock content %}
